<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="css," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="写在前面：老套路有图有真相，这才叫做分享。本文内容是：一个div里面，两个子div高度自适应（平分父div的高度）和元素内容过多的时候，根据需求出现高度滚动条或者宽度滚动条。 先放最终效果（在下面会有demo代码。）：  实现这些效果要怎么做呢？咱一步一步来。 第一步： 先设置html结构：这里我已经搭好了。12345678910111213141516171819&amp;lt;div class=&amp;q">
<meta name="keywords" content="css">
<meta property="og:type" content="article">
<meta property="og:title" content="内容滚动条和子div高度自适应">
<meta property="og:url" content="http://yoursite.com/2017/10/11/内容滚动条和子div高度自适应/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="写在前面：老套路有图有真相，这才叫做分享。本文内容是：一个div里面，两个子div高度自适应（平分父div的高度）和元素内容过多的时候，根据需求出现高度滚动条或者宽度滚动条。 先放最终效果（在下面会有demo代码。）：  实现这些效果要怎么做呢？咱一步一步来。 第一步： 先设置html结构：这里我已经搭好了。12345678910111213141516171819&amp;lt;div class=&amp;q">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-afbbb44066dd7c94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-50eb79a5c1a11982.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-b92322728420ee2e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-56f5182d46a41d3c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-41707ab6f5d8ea6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-511618e3abb59bc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-40588fbfc761809c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-8954ed3927fb04da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-83c6d190bcd5ef35.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-95bc8c9258b9b58b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-5af3a22c32a7b3ce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-8a0dd0f10f28e9b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-693f95cdf1ffe68c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/5245297-04460e8aa189b859.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2019-06-15T06:19:47.648Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="内容滚动条和子div高度自适应">
<meta name="twitter:description" content="写在前面：老套路有图有真相，这才叫做分享。本文内容是：一个div里面，两个子div高度自适应（平分父div的高度）和元素内容过多的时候，根据需求出现高度滚动条或者宽度滚动条。 先放最终效果（在下面会有demo代码。）：  实现这些效果要怎么做呢？咱一步一步来。 第一步： 先设置html结构：这里我已经搭好了。12345678910111213141516171819&amp;lt;div class=&amp;q">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/5245297-afbbb44066dd7c94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/11/内容滚动条和子div高度自适应/"/>





  <title>内容滚动条和子div高度自适应 | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/11/内容滚动条和子div高度自适应/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">内容滚动条和子div高度自适应</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-11T21:51:04+08:00">
                2017-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/css/" itemprop="url" rel="index">
                    <span itemprop="name">css</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/10/11/内容滚动条和子div高度自适应/" class="leancloud_visitors" data-flag-title="内容滚动条和子div高度自适应">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,257 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  9分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>写在前面：老套路有图有真相，这才叫做分享。本文内容是：一个div里面，两个子div高度自适应（平分父div的高度）和元素内容过多的时候，根据需求出现高度滚动条或者宽度滚动条。</p>
<p>先放最终效果（在下面会有demo代码。）：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-afbbb44066dd7c94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>实现这些效果要怎么做呢？咱一步一步来。</p>
<p>第一步：</p>
<p>先设置html结构：这里我已经搭好了。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class=&quot;box&quot;&gt;</span><br><span class="line">    &lt;div class=&quot;box1&quot;&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;!--&lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;--&gt;</span><br><span class="line">        &lt;!--&lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;--&gt;</span><br><span class="line">        &lt;!--&lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;--&gt;</span><br><span class="line">        &lt;!--&lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;--&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">    &lt;div class=&quot;box2&quot;&gt;</span><br><span class="line">        &lt;span&gt;填充填充&lt;/span&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure></p>
<p>第二步然后开始写css样式了（我会把踩坑经历放上去，所以不要一步一步走，看效果）：</p>
<p>设置父元素box的样式：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">.box&#123;</span><br><span class="line">          margin: 0 auto;</span><br><span class="line">          width: 40%;</span><br><span class="line">          background: #ccc;</span><br><span class="line">          height: 15rem;</span><br><span class="line">          border: 5px solid red; /*为了区分各个box界限*/</span><br><span class="line">      &#125;</span><br></pre></td></tr></table></figure></p>
<p>设置box1的样式：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">.box1&#123;</span><br><span class="line">            min-height: 3rem;</span><br><span class="line">            max-height: 13rem;</span><br><span class="line">            background: coral;</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure></p>
<p>现在界面是这样子的：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-50eb79a5c1a11982.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>现在尝试把html解除注释：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-b92322728420ee2e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>然后浏览器里面变成这样了。。。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-56f5182d46a41d3c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>excuse me？？？说好的滚动条呢？说好的自适应呢？</p>
<p>下面就到了关键的部分了（文章末尾有demo，不想看的话，可以自己试试。）：</p>
<p>在上面我们已经设置了最大高度和最小高度，因为box1空间不够所以溢出来了。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-41707ab6f5d8ea6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>overflow属性大家去看下，<a href="http://www.w3school.com.cn/cssref/pr_pos_overflow.asp" target="_blank" rel="noopener">http://www.w3school.com.cn/cssref/pr_pos_overflow.asp</a><br>知道你们不会去看，所以我又放图片了。。。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-511618e3abb59bc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>所以对于这部分我们要隐藏起来。 加个overflow: hidden;变成。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-40588fbfc761809c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt=" "></p>
<p>大家也都注意到了overflow: scroll;这个属性，是的，我们加上去试试。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-8954ed3927fb04da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"><br>滚动条是出来了，但是X轴的滚动条是什么鬼？<br>所以百度好久的答案，你们有福了！—————overflow-x: hidden;</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-83c6d190bcd5ef35.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>然后我顺便查到上面的简写方式。<br>原来用overflow-x: hidden;overflow-y: auto;这两行代码就可以做到！<br>我刚才是这样子的<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">.box1&#123;</span><br><span class="line">          min-height: 3rem;</span><br><span class="line">          overflow: hidden;</span><br><span class="line">          max-height: 13rem;</span><br><span class="line">          background: coral;</span><br><span class="line">          overflow: scroll;</span><br><span class="line">          overflow-x: hidden;</span><br><span class="line">      &#125;</span><br></pre></td></tr></table></figure></p>
<p>最终的代码是这样的。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">.box1&#123;</span><br><span class="line">            min-height: 3rem;</span><br><span class="line">            max-height: 13rem;</span><br><span class="line">            background: coral;</span><br><span class="line">            overflow-x: hidden;</span><br><span class="line">            overflow-y: auto;</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure></p>
<p>好了今天的内容就到这里了。。等等，好像有什么不对的地方？<br>说好的div高度自适应呢？？<br>额。。。关于这个问题，我只有一个取巧的办法。<br>我先放两张图片：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-95bc8c9258b9b58b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-5af3a22c32a7b3ce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>ps：这样就算是自适应了吧？</p>
<p>现在的情况是这样子的：<br><img src="http://upload-images.jianshu.io/upload_images/5245297-8a0dd0f10f28e9b1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>我把他们两个的背景颜色都改成一样的，再来看下：</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-693f95cdf1ffe68c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>这里也是，实际上，他的box就那么大。</p>
<p><img src="http://upload-images.jianshu.io/upload_images/5245297-04460e8aa189b859.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="Paste_Image.png"></p>
<p>写这篇花了一个半小时，主要是自己昨天才弄懂的，然后今天做demo 的时候又忘记怎么自适应div了，弄了老半天，然后用F12看昨天的代码才恍然大悟！（其实昨天没真懂，这会是真懂了），写的是真的累，码字不易，望且看且珍惜，给个喜欢吧。</p>
<p><strong>最后又到了观众朋友们最喜欢的求赞求关注环节：</strong>希望看完的朋友点个喜欢，想关注我这个菜鸡是如何成长的也可以关注一下我，基本上每个月都不会少于十五篇文章（看到干货我也会进行分享）。然后<a href="https://github.com/OBKoro1?tab=following" target="_blank" rel="noopener">github</a>也互相加个star。码字不易，感谢支持，感激不尽！</p>
<p>说好的demo，差点忘记，回来更新。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang=&quot;en&quot;&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset=&quot;UTF-8&quot;&gt;</span><br><span class="line">    &lt;title&gt;div-height-roll-demo&lt;/title&gt;</span><br><span class="line">    &lt;style&gt;</span><br><span class="line">      .box&#123;</span><br><span class="line">            margin: 0 auto;</span><br><span class="line">            width: 40%;</span><br><span class="line">            background: #ccc;</span><br><span class="line">            height: 25rem;</span><br><span class="line">            border: 5px solid red; /*为了区分各个box界限*/</span><br><span class="line">        &#125;</span><br><span class="line">        .box1&#123;</span><br><span class="line">            min-height: 3rem;</span><br><span class="line">            max-height: 13rem;</span><br><span class="line">            background: coral;</span><br><span class="line">            overflow-x: hidden;</span><br><span class="line">            overflow-y: auto;</span><br><span class="line">        &#125;</span><br><span class="line">        .box2&#123;</span><br><span class="line">            text-align: center;</span><br><span class="line">            border-top: 3px solid black;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &lt;/style&gt;</span><br><span class="line">&lt;/head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div class=&quot;box&quot;&gt;</span><br><span class="line">    &lt;div class=&quot;box1&quot;&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line">        &lt;span&gt;填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充填充&lt;/span&gt;</span><br><span class="line"></span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">    &lt;div class=&quot;box2&quot;&gt;</span><br><span class="line">        &lt;span&gt;填充填充&lt;/span&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">&lt;/body&gt;</span><br><span class="line">&lt;/html&gt;</span><br></pre></td></tr></table></figure></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/css/" rel="tag"><i class="fa fa-tag"></i> css</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/11/纵向排列文字以及禁止文字选中-1/" rel="prev" title="纵向排列文字以及禁止文字选中">
                纵向排列文字以及禁止文字选中 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

